Ever since Windows Server was first introduced back in the '90s, the tool of choice for managing system services has been the Service Control Manager. It is possible, however, to manage system services through Windows PowerShell.
You can get the services on a local or remote computer by using the Get-Service cmdlet. As with Get-Process, using the Get-Service command without parameters returns all services. You can filter by name, even using an asterisk as a wildcard.
PS> Get-Service -Name se* Status Name DisplayName ------------------------------------------------------ Running seclogon Secondary Logon Running SENS System Event Notification Stopped ServiceLayer ServiceLayer
Because it is not always obvious what the real name for the service is, you may find you need to find services by display name. You can do this by specific name, using wildcards, or using a list of display names:
PS> Get-Service -DisplayName se* Status Name DisplayName ------------------------------------------------------ Running lanmanserver Server Running SamSs Security Accounts Manager Running seclogon Secondary Logon Stopped ServiceLayer ServiceLayer Running wscsvc Security Center PS> Get-Service -DisplayName ServiceLayer,Server Status Name DisplayName ------------------------------------------------------ Running lanmanserver Server Stopped ServiceLayer ServiceLayer
You can use the ComputerName parameter of the Get-Service cmdlet to get the services on remote computers. The ComputerName parameter accepts multiple values and wildcard characters, so you can get the services on multiple computers with a single command. For example, the following command gets the services on the Server01 remote computer.
PS> Get-Service -ComputerName Server01
The Service cmdlets all have the same general form. Services can be specified by common name or display name, and take lists and wildcards as values.
PS> Stop-Service -Name service
To start the Service after it is stopped, use:
PS> Start-Service -Name service
To suspend the Service, use:
PS> Suspend-Service -Name service
The Restart-Service cmdlet works in the same manner as the other Service cmdlets, but we will show some more complex examples for it. In the simplest use, you specify the name of the service:
PS> Restart-Service -Name Service WARNING: Waiting for service 'Print Spooler (Spooler)' to finish starting... WARNING: Waiting for service 'Print Spooler (Spooler)' to finish starting... PS>